﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLToolkit;
using BLToolkit.Mapping;
using BLToolkit.DataAccess;
using DAL;
namespace Entities.PBKT
{
	[TableName("LichThiDau")]
	public class LichThiDau : BaseEntity<LichThiDau>
	{
		[MapField("MaLichTD"), PrimaryKey]
		public String MaLichThiDau { get; set; }
		public String MaDoi1 { get; set; }
		public String MaDoi2 { get; set; }
		public DateTime ThoiGian { get; set; }
		public int TrangThai { get; set; }
		public String TySo { get; set; }
		public int MaGD { get; set; }
		public String DiaDiem { get; set; }
		[MapIgnore]
		public String State
		{
			get
			{
				if (TrangThai == 0)
					return "Đang chờ thi đấu";
				else if (TrangThai == 1)
					return "Đang thi đấu";
				else if (TrangThai == 2)
					return "Kết thúc";
				else return "Hủy";
			}
		}
		//[Association(OtherKey = "IdGiaiDau", ThisKey = "MaGD")]
		//public GiaiDau GiaiDaus { get; set; }
		[MapIgnore]
		public String TenDoi1
		{
			get
			{
				DoiTuyen dt = DoiTuyen.Objects.GetById(MaDoi1);
				if (dt != null)
					return dt.TenDT;
				else
					return "";

			}
		}
		[MapIgnore]
		public String TenDoi2
		{
			get
			{
				DoiTuyen dt = DoiTuyen.Objects.GetById(MaDoi2);
				if (dt != null)
					return dt.TenDT;
				else
					return "";

			}
		}

		[MapIgnore]
		public int BanThangD1
		{
			get
			{

				String[] ts = TySo.Split('-');
				if (ts.Length >= 2)
				{
					int kq = 0;
					Int32.TryParse(ts[0], out kq);
					return kq;
				}
				else return 0;
			}
		}
		[MapIgnore]
		public int BanThangD2
		{
			get
			{
				String[] ts = TySo.Split('-');
				if (ts.Length >= 2)
				{
					int kq = 0;
					Int32.TryParse(ts[1], out kq);
					return kq;
				}
				else return 0;
			}
		}
		[MapIgnore]
		public int DiemSoDoi1
		{
			get
			{
				if (BanThangD1 > BanThangD2)
					return 3;
				else if (BanThangD1 < BanThangD2)
					return 0;
				else return 1;
			}
		}
		[MapIgnore]
		public int DiemSoDoi2
		{
			get
			{
				if (BanThangD2 > BanThangD1)
					return 3;
				else if (BanThangD2 < BanThangD1)
					return 0;
				else return 1;
			}
		}
		[MapIgnore]
		public int BanThuD1
		{
			get
			{ return BanThangD2; }
		}
		[MapIgnore]
		public int BanThuD2
		{
			get
			{ return BanThangD1; }
		}
	}
}
